#include "dlg_preserve_645_func_code.h"
#include "ui_dlg_preserve_645_func_code.h"

Dlg_preserve_645_func_code::Dlg_preserve_645_func_code(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Dlg_preserve_645_func_code)
{
    ui->setupUi(this);
    this->setWindowFlags(this->windowFlags()| Qt::WindowMaximizeButtonHint | Qt::WindowMinimizeButtonHint);
    ui->tableView->setModel(model_645_FuncCode);//sql模型与tableView绑定
    ui->tableView->resizeColumnsToContents();//列宽适应内容
    ui->tableView->setSortingEnabled(true);//排序使能
    ui->tableView->hideColumn(0);//隐藏主键列
}

Dlg_preserve_645_func_code::~Dlg_preserve_645_func_code()
{
    delete ui;
}

void Dlg_preserve_645_func_code::on_pushButtonInsetRow_clicked()
{
    int rowNum = model_645_FuncCode->rowCount(); //获得表的行数
    model_645_FuncCode->insertRow(rowNum); //添加一行
    model_645_FuncCode->setData(model_645_FuncCode->index(rowNum,1),"");//至少要在非主键单元格中执行一次写入操作，否则存在空行，会提交失败
    if(model_645_FuncCode->submitAll())
    {
        qDebug()<<"添加行成功";
    }
    else
    {
        qDebug()<<"添加行失败:"<<model_645_FuncCode->lastError().text();
    }
}

void Dlg_preserve_645_func_code::on_pushButtonDelRow_clicked()
{
    model_645_FuncCode->removeRow(ui->tableView->currentIndex().row());
    model_645_FuncCode->submitAll();//提交修改
    model_645_FuncCode->setFilter("");//相当于刷新tableView的显示
}

void Dlg_preserve_645_func_code::on_pushButtonSave_clicked()
{
    model_645_FuncCode->submitAll();
}
